package com.molihub.controller;

import com.molihub.entity.Message;
import com.molihub.service.impl.MessageServiceImpl;
import com.molihub.utils.LogUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: MessageController
 * @Description: TODO
 * @author: GGBOY
 * @date 2020/2/22 15:53
 * @Version: 1.0
 **/
@Controller
public class MessageController extends BaseController {
    private static Logger logger = LogUtils.getInstance(MessageController.class);

    /**
     * @Description 将所有的消息设为已读
     * @Author xw
     * @Date 12:59 2020/2/23
     * @Param [map]
     * @return java.lang.String
     **/
    @GetMapping("/read-all-messages")
    public String readAllMessages(Map<String,Object> map){
        messageService.setMessagesLooked(loginUser.getUserId(),0);
        return "redirect:/messages";
    }

    /**
     * @Description 删除所有消息
     * @Author xw
     * @Date 13:01 2020/2/23
     * @Param [map]
     * @return java.lang.String
     **/
    @GetMapping("/delete-all-messages")
    public String deleteMessages(Map<String,Object> map){
        messageService.deleteMessages(loginUser.getUserId(),0);
        return "redirect:/messages";
    }

    @GetMapping("/delete-message")
    public String deleteMessage(Integer id,String cur){
        if (id != null) {
            messageService.deleteMessage(id);
        }
        cur = cur == null?"new":cur;
        return "redirect:/messages?cur="+cur;
    }


}
